package com.lzm.service;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzm.mapper.ChargeprojectMapper;
import com.lzm.pojo.Chargeproject;
import com.lzm.pojo.ChargeprojectExample;
import com.lzm.pojo.Drug;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class chargeProjectService {

    @Resource
    private ChargeprojectMapper chargeprojectMapper;

    public PageInfo<Chargeproject> queryByPage(Integer pageNum,Integer pageSize,String chaP_name){
        ChargeprojectExample example = new ChargeprojectExample();
        ChargeprojectExample.Criteria criteria = example.createCriteria();
        if(chaP_name != null && !"".equals(chaP_name.trim())){
            criteria.andChaP_nameLike("%"+chaP_name.trim()+"%");
        }
        PageHelper.startPage(pageNum,pageSize);
        List<Chargeproject> chargeprojects = chargeprojectMapper.selectByExample(example);
        return new PageInfo<>(chargeprojects);
    }
    public int  add(Chargeproject chargeproject){
        chargeproject.setChaP_date(new Date());
        chargeproject.setChaP_state(0);
        return chargeprojectMapper.insertSelective(chargeproject);
    }
    public Chargeproject queryById(Integer chaP_id){
        Chargeproject chargeproject = chargeprojectMapper.selectByPrimaryKey(chaP_id);
        return chargeproject;
    }

    public int updateChargeProject(Chargeproject chargeproject){
        return chargeprojectMapper.updateByPrimaryKeySelective(chargeproject);
    }

    public int delete(Integer chaP_id){
        Chargeproject chargeproject = chargeprojectMapper.selectByPrimaryKey(chaP_id);
        chargeproject.setChaP_state(1);
        return chargeprojectMapper.updateByPrimaryKeySelective(chargeproject);
    }
}
